//
// Created by 11401 on 25-7-8.
//

#include "Task_received.h"

task_rx_t  task_rx_tx;
uint8_t t_bueff[128];
uint8_t r_bueff[128];
void bsp_task_notifications_init(UART_HandleTypeDef *huart)
{

    task_rx_t  *task_;
    task_=&task_rx_tx;
    memset(task_, 0, sizeof(task_rx_t));
    task_->huart = huart;
    task_->rx_buffer=r_bueff;
    task_->tx_buffer=t_bueff;

    HAL_UARTEx_ReceiveToIdle_IT(task_->huart,
                                task_->rx_buffer,
                                sizeof(task_->rx_buffer));
    __HAL_UART_ENABLE_IT(task_->huart,UART_IT_IDLE);
    __HAL_DMA_DISABLE_IT(&hdma_usart1_rx,DMA_IT_HT);

}


void bsp_task_notifications_tx(uint8_t *action_command,uint8_t size)
{
    HAL_UART_Transmit_DMA(task_rx_tx.huart,action_command,size);
}
void bsp_task_notifications_callback(UART_HandleTypeDef *huart, uint16_t Size)
{
    if (huart->Instance==USART1)
    {

        //队列通知
        task_notifications_dispose( task_rx_tx.rx_buffer);
        ILI9341_DispStringLine_EN(LINE(4),(char*)"sdadawdwada");

    }


    HAL_UARTEx_ReceiveToIdle_IT(task_rx_tx.huart,
                            task_rx_tx.rx_buffer,
                            sizeof(task_rx_tx.rx_buffer));
    __HAL_UART_ENABLE_IT(task_rx_tx.huart,UART_IT_IDLE);
    __HAL_DMA_DISABLE_IT(&hdma_usart1_rx,DMA_IT_HT);
}


void task_notifications_dispose(uint8_t *rx_data)
{

    uint8_t sead[25];
    if (rx_data[0]=='1')
    {
        sprintf(sead,"task_ok_seecond =%c",rx_data[0]);
        ILI9341_DispStringLine_EN(LINE(8),(char*)sead);
       BaseType_t re= xQueueSendToBackFromISR( dispatcher_task_txHandle,"a", pdMS_TO_TICKS(50) );
    }
    if (rx_data[0]=='2')
    {
        sprintf(sead,"task_ok_seecond =%c",rx_data[0]);
        ILI9341_DispStringLine_EN(LINE(8),(char*)sead);
       BaseType_t re= xQueueSendToBackFromISR( dispatcher_task_txHandle, "b", pdMS_TO_TICKS(50) );
    }
    if (rx_data[0]=='3')
    {
        sprintf(sead,"task_ok_seecond =%c",rx_data[0]);
        ILI9341_DispStringLine_EN(LINE(8),(char*)sead);
      BaseType_t re=  xQueueSendToBackFromISR( dispatcher_task_txHandle, "c", pdMS_TO_TICKS(50) );
    }
    if (rx_data[0]=='4')
    {
        sprintf(sead,"task_ok_seecond =%c",rx_data[0]);
        ILI9341_DispStringLine_EN(LINE(8),(char*)sead);
       BaseType_t re= xQueueSendToBackFromISR( dispatcher_task_txHandle, "d", pdMS_TO_TICKS(50) );
    }
    if (rx_data[0]=='5')
    {
        sprintf(sead,"task_ok_seecond =%c",rx_data[0]);
        ILI9341_DispStringLine_EN(LINE(8),(char*)sead);
       BaseType_t  re= xQueueSendToBackFromISR( dispatcher_task_txHandle, "e", pdMS_TO_TICKS(50) );
    }


}
